#include"Stack.h"
#include<stdbool.h>

typedef struct {
    Stack* s1;
    Stack* s2;

} MyQueue;


MyQueue* myQueueCreate() {
    MyQueue* ret = (MyQueue*)malloc(sizeof(MyQueue));
    ret->s1 = (Stack*)malloc(sizeof(Stack));
    ret->s2 = (Stack*)malloc(sizeof(Stack));
    StackInit(ret->s1);
    StackInit(ret->s2);
    return ret;
}

void myQueuePush(MyQueue* obj, int x) {
    StackPush(obj->s1, x);
}

int myQueuePop(MyQueue* obj) {

    while (StackSize(obj->s1) != -1)
    {
        StackPush(obj->s2, StackTop(obj->s1));
        StackPop(obj->s1);
    }
    int i = StackTop(obj->s2);
    StackPop(obj->s2);
    while (StackSize(obj->s2) != -1)
    {
        StackPush(obj->s1, StackTop(obj->s2));
        StackPop(obj->s2);
    }
    return i;
}

int myQueuePeek(MyQueue* obj) {
    while (StackSize(obj->s1) != -1)
    {
        StackPush(obj->s2, StackTop(obj->s1));
        StackPop(obj->s1);
    }
    int i = StackTop(obj->s2);
    while (StackSize(obj->s2) != -1)
    {
        StackPush(obj->s1, StackTop(obj->s2));
        StackPop(obj->s2);
    }
    return i;
}

bool myQueueEmpty(MyQueue* obj) {
    if (StackEmpty(obj->s1))
    {
        return true;
    }
    return false;
}

void myQueueFree(MyQueue* obj) {
    StackDestroy(obj->s1);
    StackDestroy(obj->s2);
    free(obj);
}

int main()
{
    MyQueue* obj = myQueueCreate();
    myQueuePush(obj, 1);
    myQueuePush(obj, 2);

    int param_2 = myQueuePop(obj);

    int param_3 = myQueuePeek(obj);

    bool param_4 = myQueueEmpty(obj);

    myQueueFree(obj);
}
 
